#!/bin/bash
read -p "请输入你现在使用的数据库ROOT用户密码" dbpass
read -p "请输入新的数据ROOT用户密码" newdbpass
mysql -uroot -p$dbpass -e "use mysql"
mysql -uroot -p$dbpass -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '$newdbpass' WITH GRANT OPTION;"
read -p "是否开启ROOT用户远程登陆权限[y/n]" m
if [ $m == y ];then
	mysql -uroot -p$newdbpass -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '$newdbpass' WITH GRANT OPTION;"
else
	echo -e '正在配置'
fi
mysql -uroot -p$newdbpass -e "flush privileges;"
echo -e '数据库ROOT用户密码已修改为$newdbpass，请使用新密码登陆数据库
 如若之前已使用该密码配置过相关服务请自己手动去更新'

